package org.bet.domain;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.util.Assert;

@Document
public class Assembly extends AbstractIDAssignedObject {
	private static final long serialVersionUID = 863997956744968077L;

	@Indexed
	private String name;
	private String description;
	
	@DBRef
	private Genome genome;
	private long size;
		
	public Assembly(String name, Genome genome) {
		super(generateId(name, genome));
	
		Assert.hasText(name, "name should be not empty");
		Assert.notNull(genome, "genome should be not null");
		this.name = name;
		this.genome = genome;		
	}

	protected static String generateId(String name, Genome genome) {
		return genome.getId() + ":" + name;
	}

	public long getSize() {
		return size;
	}

	public void setSize(long size) {
		this.size = size;
	}

	public String getName() {
		return name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Genome getGenome() {
		return genome;
	}

	private void setGenome(Genome genome) {
		this.genome = genome;
	}
	
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
}
